#include <iostream>
#include <unordered_map>
#include <ctime>
using namespace std;

#define DBG_LEVEL 0
#define INF_LEVEL 1
#define ERR_LEVEL 2
#define DEFAULT_LEVEL DBG_LEVEL //默认日志等级，控制哪些日志能输出，哪些不能

unordered_map<int, string> hash_level = {
    {DBG_LEVEL, "Debug"}, 
    {INF_LEVEL, "Info "},
    {ERR_LEVEL, "Error"}
};

#define LOG(level, format, ...) {\
    if (level >= DEFAULT_LEVEL) {\
        time_t t = time(nullptr);\
        struct tm* ptm = localtime(&t);\
        char time_str[32];\
        strftime(time_str, 31, "%Y-%m-%d %H:%M:%S", ptm);\
        printf("[%s][%s][%s:%d]   " format "\n", hash_level[level].c_str(), time_str, __FILE__, __LINE__, ##__VA_ARGS__);\
    }\
} 

#define DLOG(format, ...) LOG(DBG_LEVEL, format, ##__VA_ARGS__);
#define ILOG(format, ...) LOG(INF_LEVEL, format, ##__VA_ARGS__);
#define ELOG(format, ...) LOG(ERR_LEVEL, format, ##__VA_ARGS__);

int main()
{
    LOG(ERR_LEVEL, "Hello %s--%d", "World", 5);
    DLOG("Hello %s--%d", "World", 5);
    ILOG("Hello %s--%d", "World", 5);
    ELOG("Hello %s--%d", "World", 5);
    return 0;
}